<?php
/*************************************************************************************
   Copyright notice

   This script uses some code parts of the glossary module for phpwcms (c) Oliver Georgi
   (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.

   This script uses some code parts from bmcatalog module
   (c) 2010 Benjamin Matzmorr, www.etype.de

   (c) 2012 webrealisierung gmbh, www.webrealisierung.ch
   Catalogue Module V 1.0.0  -  Date: 2012-06-01

   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license
   from the author is found in LICENSE.txt distributed with these scripts.

   This script is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.

   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/
// ----------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day.");
}
// ----------------------------------------------------------------


$plugin_ctg = array();

  $plugin_ctg['cp_id'] = intval($_POST["cid"]);
  //check for the next cp id when creating a new cp
  //neccessary because at this point phpwcms hasn't set the cp id yet when new cp
  if($_POST["cid"]==0) {
      $plugin_ctg['cp_id_sql'] = mysql_query("SHOW TABLE STATUS LIKE '".DB_PREPEND."phpwcms_articlecontent'") or die("Error: ".mysql_error());
      $plugin_ctg['cp_id_data'] = mysql_fetch_assoc($plugin_ctg['cp_id_sql']);
      $plugin_ctg['cp_id'] = $plugin_ctg['cp_id_data']['Auto_increment'];
  }


// This handles module content part POST values
$content['br_catalogue'] = array();

$content['br_catalogue']['ctg_catalogs']	= array();
if ( !empty($_POST['ctg_catalogs']) ) $content['br_catalogue']['ctg_catalogs']	= array_map('intval', $_POST['ctg_catalogs']);

$content['br_catalogue']['ctg_tmpl']				= clean_slweg($_POST['ctg_tmpl']);
$content['br_catalogue']['ctg_css']				= clean_slweg($_POST['ctg_css']);

$content['br_catalogue']['ctg_filter1']			= clean_slweg($_POST['ctg_filter1']);
$content['br_catalogue']['ctg_filter2']			= clean_slweg($_POST['ctg_filter2']);
$content['br_catalogue']['ctg_filter3']			= clean_slweg($_POST['ctg_filter3']);
$content['br_catalogue']['ctg_filter4']			= clean_slweg($_POST['ctg_filter4']);
$content['br_catalogue']['ctg_fltr1_render']		= empty( $_POST['ctg_fltr1_render'] ) ? 'ul' : clean_slweg($_POST['ctg_fltr1_render']);
$content['br_catalogue']['ctg_fltr0_render']		= empty( $_POST['ctg_fltr0_render'] ) ? 'ul' : clean_slweg($_POST['ctg_fltr0_render']);
$content['br_catalogue']['ctg_fltr0_dflt']			= empty( $_POST['ctg_fltr0_dflt'] ) ? 'default' : clean_slweg($_POST['ctg_fltr0_dflt']);
$content['br_catalogue']['ctg_fltr1_dflt']			= empty( $_POST['ctg_fltr1_dflt'] ) ? 'default' : clean_slweg($_POST['ctg_fltr1_dflt']);
$content['br_catalogue']['ctg_fltr2_dflt']			= empty( $_POST['ctg_fltr2_dflt'] ) ? 'default' : clean_slweg($_POST['ctg_fltr2_dflt']);
$content['br_catalogue']['ctg_fltr3_dflt']			= empty( $_POST['ctg_fltr3_dflt'] ) ? 'default' : clean_slweg($_POST['ctg_fltr3_dflt']);
$content['br_catalogue']['ctg_fltr4_dflt']			= empty( $_POST['ctg_fltr4_dflt'] ) ? 'default' : clean_slweg($_POST['ctg_fltr4_dflt']);

$content['br_catalogue']['ctg_imgwidth']				= clean_slweg($_POST['ctg_imgwidth']);
$content['br_catalogue']['ctg_imgheight']				= clean_slweg($_POST['ctg_imgheight']);
$content['br_catalogue']['ctg_imgcrop']				=  empty($_POST['ctg_imgcrop']) ? 0 : 1;
$content['br_catalogue']['ctg_imgrand']				=  empty($_POST['ctg_imgrand']) ? 0 : 1;

$content['br_catalogue']['ctg_imgwidth_detail']				= clean_slweg($_POST['ctg_imgwidth_detail']);
$content['br_catalogue']['ctg_imgheight_detail']				= clean_slweg($_POST['ctg_imgheight_detail']);
$content['br_catalogue']['ctg_imgcrop_detail']				=  empty($_POST['ctg_imgcrop_detail']) ? 0 : 1;
$content['br_catalogue']['ctg_imgzoom_detail']				=  empty($_POST['ctg_imgzoom_detail']) ? 0 : 1;
$content['br_catalogue']['ctg_imgrand_detail']				=  empty($_POST['ctg_imgrand_detail']) ? 0 : 1;

$content['br_catalogue']['ctg_usegooglemaps']			= empty($_POST['ctg_usegooglemaps']) ? 0 : 1;
$content['br_catalogue']['ctg_googlemapscenterzoom']	= intval($_POST['ctg_googlemapscenterzoom']);
$content['br_catalogue']['ctg_listhtml']	= empty($_POST['ctg_listhtml']) ? 0 : 1;

//image gallery 0 from folder

//listing images
//is width/height set in cp-settings? else use phpwcms standard list sizes - Images for Listings
  $plugin_ctg['ctg_imgwidth'] = ($content['br_catalogue']['ctg_imgwidth']==0   || isempty($content['br_catalogue']['ctg_imgwidth']))  ? ""  : intval($content['br_catalogue']['ctg_imgwidth']);
  $plugin_ctg['ctg_imgheight'] = ($content['br_catalogue']['ctg_imgheight']==0 || isempty($content['br_catalogue']['ctg_imgheight'])) ? "" : intval($content['br_catalogue']['ctg_imgheight']);
  if ( empty($plugin_ctg['ctg_imgwidth']) && empty($plugin_ctg['ctg_imgheight']) ) {
    $plugin_ctg['ctg_imgwidth'] = $phpwcms['img_list_width'];
    $plugin_ctg['ctg_imgheight'] = $phpwcms['img_list_height'];
  }
  $plugin_ctg['ctg_imgcrop'] = $content['br_catalogue']['ctg_imgcrop'];

//detail images
//is width/height set in cp-settings? else use phpwcms standard list sizes - Images for Detail View
    $plugin_ctg['ctg_imgwidth_detail'] = ($content['br_catalogue']['ctg_imgwidth_detail']==0   || isempty($content['br_catalogue']['ctg_imgwidth_detail']))  ? ""  : intval($content['br_catalogue']['ctg_imgwidth_detail']);
    $plugin_ctg['ctg_imgheight_detail'] = ($content['br_catalogue']['ctg_imgheight_detail']==0 || isempty($content['br_catalogue']['ctg_imgheight_detail'])) ? "" : intval($content['br_catalogue']['ctg_imgheight_detail']);
    if ( empty($plugin_ctg['ctg_imgwidth_detail']) && empty($plugin_ctg['ctg_imgwidth_detail']) ) {
      $plugin_ctg['ctg_imgwidth_detail'] = $phpwcms['img_list_width'];
      $plugin_ctg['ctg_imgheight_detail'] = $phpwcms['img_list_height'];
    }
  $plugin_ctg['ctg_imgcrop_detail'] = $content['br_catalogue']['ctg_imgcrop_detail'];

//get catalog entries
  $plugin_ctg['sql'] = 'SELECT * FROM '.DB_PREPEND.'phpwcms_mod_catalogue_entry WHERE ctge_status=1';
//in given Catalogs
  if (count($content['br_catalogue']['ctg_catalogs'])) {
    foreach( $content['br_catalogue']['ctg_catalogs'] as $v ) {
    	$plugin_ctg['catid'][] = "ctge_catalogid LIKE '%|".$v."|%'";
    }
  } 

	if(count($plugin_ctg['catid'])) {
		$plugin_ctg['sql'] .= ' AND ('.implode(' OR ', $plugin_ctg['catid']).')';
	} else {
    $plugin_ctg['sql'] .= " AND ctge_catalogid = 'allcats'"; //never true
  }

  $plugin_ctg['data']  = _dbQuery($plugin_ctg['sql']);

//loop through every entry ...
		foreach($plugin_ctg['data'] as $ekey => $evalue) {

      //unserialize ctge_image
      $plugin_ctg['entries']['ctge_image'] =	@unserialize($evalue['ctge_image']);

      //which gallery?
      if ($plugin_ctg['entries']['ctge_image'][1]['active'] == 1) { //images from folder

        $ctg_folder_imgs = $plugin_ctg['entries']['ctge_image'][1];
          /*
          $ctg_folder_imgs['root']
          $ctg_folder_imgs['pag']
          $ctg_folder_imgs['pagnr']
          */

        //init vars
        $error = '';
        $ctg_folder_thumbdir = 'thumbs'; //name for thumbnail folder
        $delim = DIRECTORY_SEPARATOR;
        $ctg_folder_filename = '';
        $ctg_folder_file = '';
        $dirs = $pics = array();
        $jpg = '\.jpg$|\.jpeg$'; $jpg2 = '\.JPG$'; $gif = '\.gif$'; $png = '\.png$';

        //get the root folder without slash
        $dd = rtrim($phpwcms['modules'][$content["module"]]['path'].$ctg_folder_imgs['root'],'/');

        $query = $jpg;
        if (function_exists('imagecreatefromgif')) $query .= "|$gif";
        if (function_exists('imagecreatefrompng')) $query .= "|$png";

        if (($d = opendir($dd)) === false) $error = "Cannot open directory";
        while (($ctg_folder_filename = readdir($d)) !== false) {
          if ($ctg_folder_filename == $ctg_folder_thumbdir
         //  || ($ctg_folder_filename == '..' && $dirname == '')
           || ($ctg_folder_filename != '..' && substr($ctg_folder_filename, 0, 1) == '.')) continue;
          $ctg_folder_file = $dd . $delim . $ctg_folder_filename;

        if (is_dir($ctg_folder_file)) $dirs[] = $ctg_folder_filename;
            elseif (eregi($query, $ctg_folder_file)) $pics[] = $ctg_folder_filename;
        }
        closedir($d);

        //loop through pics in folder, create thumbnail if not exists
        foreach ($pics as $val) {
            $ctg_folder_filename = $val;
            $ctg_folder_file = $dd . $delim . $ctg_folder_filename;
            //if (!is_readable($ctg_folder_file)) continue;
            if (!is_dir($dd . $delim . $ctg_folder_thumbdir)) {
             $u = umask(0);
             if (!mkdir($dd . $delim . $ctg_folder_thumbdir, 0777)) {
              $error = 'Cannot create new directory';
              break;
             }
             umask($u);
            }
            if (ereg($jpg, $ctg_folder_file)) {
              $ext = 'jpg';
            } elseif (ereg($jpg2, $ctg_folder_file)) {
              $ext = 'JPG';
            } elseif (eregi($gif, $ctg_folder_file)) {
              $ext = 'gif';
            } elseif (eregi($png, $ctg_folder_file)) {
              $ext = 'png';
            }

            //thumbs are generated with phpwcms function to given folder EACH TIME the CP is updated
              //if (!is_file($thumb)) {

            //1. for listingimages
              $default = array(    "max_width"        =>    $plugin_ctg['ctg_imgwidth'],
                                "max_height"    =>    $plugin_ctg['ctg_imgheight'],
                                "error"            =>    0,
                                "image_name"    =>    $ctg_folder_filename,
                                "thumb_name"    =>    'tmblst_'.$plugin_ctg['cp_id'].'_'.basename($ctg_folder_filename, ".".$ext),
                                "target_ext"    =>    $ext,
                                "image_dir"        =>    $dd . $delim,
                                "thumb_dir"        =>    $dd . $delim . $ctg_folder_thumbdir . $delim,
                                'jpg_quality'    =>    100,
                                'sharpen_level'    =>    0,
                                'density'        =>    72,
                                'add_command'    =>    '',
                                'crop_image'    =>    $plugin_ctg['ctg_imgcrop']
                            );
              $create_preview = imagick_converting( $default );
            //2. for detailimages
              $detailimg = array(    "max_width"        =>    $plugin_ctg['ctg_imgwidth_detail'],
                                "max_height"    =>    $plugin_ctg['ctg_imgheight_detail'],
                                "error"            =>    0,
                                "image_name"    =>    $ctg_folder_filename,
                                "thumb_name"    =>    'tmbdet_'.$plugin_ctg['cp_id'].'_'.basename($ctg_folder_filename, ".".$ext),
                                "target_ext"    =>    $ext,
                                "image_dir"        =>    $dd . $delim,
                                "thumb_dir"        =>    $dd . $delim . $ctg_folder_thumbdir . $delim,
                                'jpg_quality'    =>    100,
                                'sharpen_level'    =>    0,
                                'density'        =>    72,
                                'add_command'    =>    '',
                                'crop_image'    =>    $plugin_ctg['ctg_imgcrop_detail']
                            );
              $create_preview = imagick_converting( $detailimg );

              //}

        } //end foreach
      } //end images from folder
		} //end foreach

unset($plugin_ctg['sql'], $plugin_ctg['data']);
//end image gallery 0 from folder


//rss creation
  $content['br_catalogue']['ctg_rss_active'] = empty($_POST['ctg_rss_active']) ? 0 : 1;
  $content['br_catalogue']['ctg_rss_title'] = empty( $_POST['ctg_rss_title'] ) ? '' : clean_slweg($_POST['ctg_rss_title']);
  $content['br_catalogue']['ctg_rss_descr'] = empty( $_POST['ctg_rss_descr'] ) ? '' : clean_slweg($_POST['ctg_rss_descr']);

  if (empty($_POST['ctg_rss_number'])) {
    if(isset($_POST['ctg_rss_active']) && $_POST['ctg_rss_active'] == 1) {
      $content['br_catalogue']['ctg_rss_number'] = 10;
    } else {
      $content['br_catalogue']['ctg_rss_number'] = '';
    }
  } else {
    $content['br_catalogue']['ctg_rss_number'] = intval($_POST['ctg_rss_number']);
  }

//rss render xml file to content/rss/
  if( count($content['br_catalogue']['ctg_catalogs']) && $content['br_catalogue']['ctg_rss_active'] == 1 ) {

    include_once($phpwcms['modules'][$content["module"]]['path'].'inc/ctg.front.func.inc.php');
    require_once (PHPWCMS_ROOT.'/include/inc_ext/feedcreator/feedcreator.class.php');

    $plugin_ctg['feeds_formats']	= array('0.91', 'RSS0.91', '1.0', 'RSS1.0', '2.0', 'RSS2.0', 'ATOM', 'ATOM1.0', 'ATOM0.3');
    $plugin_ctg['feeds'] 			= array();
    $plugin_ctg['feeds']['default'] = array(
  								"title"				=> $content['br_catalogue']['ctg_rss_title'],
  								"description"		=> $content['br_catalogue']['ctg_rss_descr'],
  								"link"				=> PHPWCMS_URL,
  								"syndicationURL"	=> "",
  								"imagesrc"			=> "",
  								"imagetitle"		=> "",
  								"imagelink"			=> "",
  								"imagedescription"	=> "",
  								"timeZone"			=> "+01:00",
  								"cacheTTL"			=> 3600,
  								"structureID"		=> "",
  								"useauthor"			=> 1,
  								"feedAuthor"		=> "",
  								"maxentries"		=> $content['br_catalogue']['ctg_rss_number'],
  								"encoding"			=> "UTF-8",
  								"defaultFormat"		=> "RSS2.0",
  								"filename"			=> "default_feed.xml",
                  "locale"   =>  "de_DE",
                  "dateformat"   =>  "%A, %d. %B %Y"
  							  );

  $CTG_FEED = $plugin_ctg['feeds']['default'];
  $CTG_FEED['defaultFormat']	= empty($_GET['format']) ? trim($CTG_FEED['defaultFormat']) : strtoupper(clean_slweg($_GET['format']));
  $CTG_FEED['defaultFormat']	= in_array($CTG_FEED['defaultFormat'], $plugin_ctg['feeds_formats']) ? $CTG_FEED['defaultFormat'] : "RSS2.0";
  $CTG_FEED['filename']		=  CONTENT_PATH.'rss/feed-catalog-'.intval($_POST["caid"]).'-'.$plugin_ctg['cp_id'].'.xml';
  $CTG_FEED['maxentries']		= intval($CTG_FEED['maxentries']);
  $CTG_FEED['useauthor']		= intval($CTG_FEED['useauthor']);
  $CTG_FEED['encoding']		= empty($CTG_FEED['encoding']) ? 'utf-8' : $CTG_FEED['encoding'];

  define('FEED_ENCODING', trim(strtolower($CTG_FEED['encoding'])));
  define("TIME_ZONE","+01:00");

  $rss 	= new UniversalFeedCreator();
  //$rss->useCached($CTG_FEED['defaultFormat'], $CTG_FEED['filename'], intval($CTG_FEED['cacheTTL']));
  $rss->title 				    = cm_combinedParser($CTG_FEED['title'], FEED_ENCODING);
  $rss->description 			= cm_combinedParser($CTG_FEED['description'], FEED_ENCODING);
  $rss->link 					    = $CTG_FEED['link'];
  $rss->syndicationURL 		= $CTG_FEED['syndicationURL'];
  $rss->encoding				  = FEED_ENCODING;
  if(!empty($CTG_FEED['feedAuthor'])) {
  	$rss->editor			= $CTG_FEED['feedAuthor'];
  }
  if(!empty($CTG_FEED['feedEmail'])) {
  	$rss->editorEmail		= $CTG_FEED['feedEmail'];
  }

  if(!empty($CTG_FEED['imagesrc'])) {

  	$image 					      = new FeedImage();
  	$image->title 			  = $CTG_FEED['imagetitle'];
  	$image->url 			    = $CTG_FEED['imagesrc'];
  	$image->link			    = $CTG_FEED['imagelink'];
  	$image->description		= $CTG_FEED['imagedescription'];
  	$rss->image 			    = $image;

  }

  $plugin_ctg['catarray'] = array();
  foreach($content['br_catalogue']['ctg_catalogs'] as $val) {
      $plugin_ctg['catarray'][] = "ctge_catalogid LIKE '%|".aporeplace(intval($val))."|%'";
  }
  $plugin_ctg['wherequery'] = (count($plugin_ctg['catarray'])) ? " AND (".implode(' OR ', $plugin_ctg['catarray']).")" : " AND ctge_allcats = '0'"; //then statement is never true

//todo may be filtered as well
  $plugin_ctg["sql"]  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_mod_catalogue_entry WHERE ';
  $plugin_ctg["sql"] .= "ctge_status = 1";
  $plugin_ctg["sql"] .= $plugin_ctg['wherequery'];
  $plugin_ctg["sql"] .= " ORDER BY ctge_title";

  if($CTG_FEED['maxentries']) {
  	$plugin_ctg["sql"] .= " LIMIT ".$CTG_FEED['maxentries'];
  }
  $plugin_ctg["data"] = _dbQuery($plugin_ctg["sql"]);


  $plugin_ctg["timeplus"] = 0;
  	if( !isset($plugin_ctg["data"][0]) ) {
      $plugin_ctg["output"]		= '\n';
    } else {
      foreach ($plugin_ctg["data"] as $value) {
  	    $value['ctge_entry_image'] = unserialize(	$value['ctge_image']);

    		$item = new FeedItem();
    		$item->title 			= cm_combinedParser($value['ctge_title'], FEED_ENCODING);
    		$item->link 			= PHPWCMS_URL.'index.php?aid='.intval($_POST["caid"]).'&ctg_id='.$value['ctge_id'];
        setlocale(LC_TIME, $CTG_FEED['locale'].".UTF-8");
        $desr =  cm_combinedParser( $value['ctge_title2'] , FEED_ENCODING)."<br />";
        $desr .=  cm_combinedParser( $value['ctge_text'] , FEED_ENCODING)."<br />";
        $desr .=   cm_combinedParser( empty($value['ctge_text2']) ? '' : $value['ctge_text2'] , FEED_ENCODING)  ;
    		$item->description 		= $desr;
    		$item->date 			= strtotime($value['ctge_changed']) + $plugin_ctg["timeplus"];
        $item->updateDate		= strtotime($value['ctge_changed'])  + $plugin_ctg["timeplus"] + 1;

       //image
        if( !empty($value['ctge_entry_image'][0]['ctge_images'][0]) && $value['ctge_entry_image'][0]['active'] == 1 ) { //phpwcms image

  		    $plugin_ctg["sql_img"] = 'SELECT * FROM '.DB_PREPEND.'phpwcms_file WHERE f_aktiv=1 AND f_public=1 AND f_id='.$value['ctge_entry_image'][0]['ctge_images'][0];
  		    $plugin_ctg["data_img"] = _dbQuery($plugin_ctg["sql_img"]);

          if(isset($plugin_ctg["data_img"][0])) {
            $plugin_ctg["thumbsize"] = @getimagesize(PHPWCMS_FILES.$plugin_ctg["data_img"][0]["f_hash"] . '.' . $plugin_ctg["data_img"][0]["f_ext"]);

            $plugin_ctg["item_img"]	 = get_cached_image(
    						array(	"target_ext"	=>	$plugin_ctg["data_img"][0]["f_ext"],
    								"image_name"	=>	$plugin_ctg["data_img"][0]["f_hash"] . '.' . $plugin_ctg["data_img"][0]["f_ext"],
    								"max_width"		=>	$plugin_ctg["thumbsize"][0],
    								"max_height"	=>	$plugin_ctg["thumbsize"][1],
    								"thumb_name"	=>	md5(	$plugin_ctg["data_img"][0]["f_hash"].$plugin_ctg["thumbsize"][0].
    															$plugin_ctg["thumbsize"][1].$GLOBALS['phpwcms']["sharpen_level"])
    						)
            	);

            //<enclosure url="http://example.com/image.jpg" length="12216320" type="images/jpeg" />
            //$item->enclosure
            $item->enclosure->url = PHPWCMS_URL.PHPWCMS_IMAGES.$plugin_ctg["item_img"][0];
            $item->enclosure->length = filesize(PHPWCMS_ROOT.'/'.PHPWCMS_IMAGES.$plugin_ctg["item_img"][0]);
            $item->enclosure->type = "images/jpeg";
          }

        } else if ($value['ctge_entry_image'][1]['active'] == 1) { //img from folder

          $plugin_ctg["imgfolder"] = opendir($phpwcms['modules'][$content["module"]]['path'].$value['ctge_entry_image'][1]['root']);

          $plugin_ctg["pic_types"] = array("jpg", "jpeg", "gif", "png");
          $plugin_ctg["folderpics"] = array();
          while ($file = readdir ($plugin_ctg["imgfolder"])) {
            if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$plugin_ctg["pic_types"]) ) {
              array_push($plugin_ctg["folderpics"],$file);
            }
          }
          closedir($plugin_ctg["imgfolder"]);
          if (count($plugin_ctg["folderpics"])) {
            $item->enclosure->url = PHPWCMS_URL.$phpwcms['modules'][$content["module"]]['dir'].$value['ctge_entry_image'][1]['root'].$plugin_ctg["folderpics"][0];
            $item->enclosure->length = filesize(PHPWCMS_ROOT.'/'.$phpwcms['modules'][$content["module"]]['dir'].$value['ctge_entry_image'][1]['root'].$plugin_ctg["folderpics"][0]);
            $item->enclosure->type = "images/jpeg";
          }

        } //end imgage

    		$item->source = PHPWCMS_URL;
    		if($CTG_FEED['useauthor'] || $CTG_FEED['defaultFormat'] == 'ATOM' || $CTG_FEED['defaultFormat'] == 'ATOM1.0') {
    				$item->author 	= $CTG_FEED['feedAuthor'];
    		}
    		$item->guid				= PHPWCMS_URL.'index.php?aid='.intval($_POST["caid"]).'&ctg_id='.$value['ctge_id'];
    		$rss->addItem($item);
    		$plugin_ctg["timeplus"] += 2;
	    } //end foreach
    } //end if data

    //write the file
    $rss->saveFeed($CTG_FEED['defaultFormat'], $CTG_FEED['filename'], false);

  } //end if rss active and catalogs selected
  unset($plugin_ctg);

?>